package com.example.qxfw.backgroundManagement.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;

import com.example.qxfw.common.entity.Roles;
import com.example.qxfw.common.entity.UserTable;

import com.example.qxfw.common.entity.ny.StationInfo;
import com.example.qxfw.common.entity.xt.Users;
import org.apache.ibatis.annotations.*;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/4  星期二   10:43
 * @description : 此类用来 用户管理2 的底层数据交互
 ***************************************/
@Mapper
@DS("service")
public interface UserManagementSecondMapper {

    @Select("select username, password, servicewebaddress, servicewechataddress, inputtime, performer " +
            "from user_table")
    List<UserTable> selectUserTable();

    @Select("select id, role from roles")
    List<Roles> selectRoles();

    @Select("select stationid, stationname, county, township, village, city " +
            "from station_info")
    List<StationInfo> selectStationInfo();

    @Select("select id, username, password, servicewebaddress, servicewechataddress, inputtime, performer, permission, reservoirid, reservoirname, drainagearea, county, lon, lat, range " +
            "from user_table " +
            "where username = #{userName}")
    List<UserTable> selectByUserName(String userName);

    @Insert("insert into users(username,password,type,stationid,ownercity,ownercounty,ownertown,ownervillage) " +
            "values (#{users.username},#{users.password},#{users.type},#{users.stationid},#{users.ownercity},#{param1.ownercounty},#{users.ownertown},#{param1.ownervillage})")
    Integer insertUsers(@Param("users") Users users);
    @Insert("insert into user_table(username, password, servicewebaddress, servicewechataddress, inputtime, performer, permission) " +
            "values (#{userTable.username},#{userTable.password},#{userTable.servicewebaddress},#{userTable.servicewechataddress},#{userTable.inputtime},#{userTable.performer},#{userTable.permission})")
    Integer insertUserTable(@Param("userTable") UserTable userTable);

    @Select("select username,password,type from users where username=#{userName} and type =#{type}")
    List<Users> selectByUserNameAndType(@Param("userName") String userName, @Param("type") String type);

    @Update("update user_table " +
            "set password=#{userTable.password},servicewebaddress=#{userTable.servicewebaddress},servicewechataddress=#{userTable.servicewechataddress},inputtime=#{userTable.inputtime},performer=#{userTable.performer} " +
            "where username=#{userTable.username}")
    Integer updateUserTable(@Param("userTable") UserTable userTable);

    @Update("update users " +
            "set stationid = #{users.stationid},ownercity=#{users.ownercity},ownercounty=#{users.ownercounty},ownertown=#{users.ownertown},ownervillage=#{users.ownervillage} " +
            "where username  = #{users.username} and type = #{users.type}")
    Integer updateUsers(@Param("users") Users users);

    @Select("<script> " +
            "select id, username, password, servicewebaddress, servicewechataddress, inputtime, performer, permission, reservoirid, reservoirname, drainagearea, county, lon, lat, range " +
            "from user_table where 1=1 " +
            "<if test='username!=null'>and username like concat('%',#{username},'%')</if>" +
            "<if test='starttime!=null and endtime!=null'>and inputtime between #{starttime} and #{endtime}</if>" +
            "</script>")
    List<UserTable> querySelect(@Param("starttime") String starttime, @Param("endtime") String endtime, @Param("username") String username);

    @Select("select id, stationid, username, password, ownercity, ownercounty, ownertown, ownervillage, type, remarks " +
            "from users where username = #{username}")
    List<Users> selectUsersByUsername( String username);

}
